package hot.job.core.holder;

import hot.job.core.meta.JobMeta;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * holder for hot job meta infos
 *
 * @author gaowenhao
 * @since 2022/7/11 19:37
 */
public class HotJobMetaHolder {

    private static final Map<String, JobMeta> metaMap = new HashMap<>();

    public static void hold(String key, JobMeta meta){
        synchronized (HotJobMetaHolder.class){
            if(metaMap.containsKey(key)){
                throw new RuntimeException("duplicated hot job key has been found, key : \"" + key + "\" must be unique");
            }
            metaMap.put(key, meta);
        }
    }


    public static JobMeta get(String key){
        return metaMap.get(key);
    }


    public static Map<String, JobMeta> getReadableMap(){
        return Collections.unmodifiableMap(metaMap);
    }

}
